/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bookshop.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Thibault
 */
@Entity
@Table(catalog = "bookshopdb", schema = "", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"id"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Customerorder.findAll", query = "SELECT c FROM Customerorder c"),
    @NamedQuery(name = "Customerorder.findById", query = "SELECT c FROM Customerorder c WHERE c.id = :id"),
    @NamedQuery(name = "Customerorder.findByAmount", query = "SELECT c FROM Customerorder c WHERE c.amount = :amount"),
    @NamedQuery(name = "Customerorder.findByConfirmationNumber", query = "SELECT c FROM Customerorder c WHERE c.confirmationNumber = :confirmationNumber"),
    @NamedQuery(name = "Customerorder.findByCreatedDate", query = "SELECT c FROM Customerorder c WHERE c.createdDate = :createdDate"),
    @NamedQuery(name = "Customerorder.findByCanceledDate", query = "SELECT c FROM Customerorder c WHERE c.canceledDate = :canceledDate"),
    @NamedQuery(name = "Customerorder.findByCustomerId", query = "SELECT c FROM Customerorder c WHERE c.customerid = :customerid and c.confirmationNumber= :confirmationNumber")
})
public class Customerorder implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false, precision = 5, scale = 2)
    private double amount;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private int confirmationNumber;
    @Basic(optional = false)
    //@NotNull
    @Column(nullable = true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Temporal(TemporalType.TIMESTAMP)
    private Date canceledDate;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customerorder", fetch = FetchType.LAZY)
    private List<CustomerorderBook> customerorderBookList;
    @JoinColumn(name = "Customer_id", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Customer customerid;

    public Customerorder() {
    }

    public Customerorder(Integer id) {
        this.id = id;
    }

    public Customerorder(Integer id, double amount, int confirmationNumber, Date createdDate) {
        this.id = id;
        this.amount = amount;
        this.confirmationNumber = confirmationNumber;
        this.createdDate = createdDate;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public int getConfirmationNumber() {
        return confirmationNumber;
    }

    public void setConfirmationNumber(int confirmationNumber) {
        this.confirmationNumber = confirmationNumber;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Date getCanceledDate() {
        return canceledDate;
    }

    public void setCanceledDate(Date canceledDate) {
        this.canceledDate = canceledDate;
    }

    @XmlTransient
    public List<CustomerorderBook> getCustomerorderBookList() {
        return customerorderBookList;
    }

    public void setCustomerorderBookList(List<CustomerorderBook> customerorderBookList) {
        this.customerorderBookList = customerorderBookList;
    }

    public Customer getCustomerid() {
        return customerid;
    }

    public void setCustomerid(Customer customerid) {
        this.customerid = customerid;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customerorder)) {
            return false;
        }
        Customerorder other = (Customerorder) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Customerorder{" + "id=" + id + ", amount=" + amount + ", confirmationNumber=" + confirmationNumber + ", createdDate=" + createdDate + ", canceledDate=" + canceledDate + ", customerorderBookList=" + customerorderBookList + ", customerid=" + customerid + '}';
    }
}
